package com.community.backend.service.impl;

import com.community.backend.mapper.VisitorMapper;
import com.community.backend.pojo.Visitor;
import com.community.backend.pojo.dto.VisitorQueryDTO;
import com.community.backend.service.VisitorService;
import com.community.backend.utils.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

@Service
public class VisitorServiceImpl implements VisitorService {
    private final VisitorMapper visitorMapper;

    public VisitorServiceImpl(VisitorMapper visitorMapper) {
        this.visitorMapper = visitorMapper;
    }

    @Override
    public PageResult pageQuery(VisitorQueryDTO visitorQueryDTO) {
        PageHelper.startPage(visitorQueryDTO.getCurrentPage(),visitorQueryDTO.getPageSize());
        Page<Visitor> page = visitorMapper.pageQuery(visitorQueryDTO);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void insert(Visitor visitor) {
        visitorMapper.insert(visitor);
    }

    @Override
    public void deleteById(Integer id) {
        visitorMapper.deleteById(id);
    }

    @Override
    public void update(Visitor visitor) {
        visitorMapper.update(visitor);
    }

    @Override
    public Visitor selectById(Integer id) {
        Visitor visitor = visitorMapper.selectById(id);
        return visitor;
    }
}
